package com.dream.keigezhushou.Activity.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.bean.TicketInfo;
import com.dream.keigezhushou.R;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GetTicketCentreActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.lq)
    RelativeLayout mLq;

    private PullToRefreshListView mPull;
    private ArrayList<TicketInfo> list = new ArrayList<>();
    private MyAdapter mMyAdapter;
   // private  int currposition;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_ticket_centre);
        ButterKnife.bind(this);

        mPull = (PullToRefreshListView) findViewById(R.id.list_centre);


        ListView mlist = mPull.getRefreshableView();

        ImageView ivback = (ImageView) findViewById(R.id.back);
        ivback.setOnClickListener(this);
        initData();
        mMyAdapter = new MyAdapter(getApplicationContext());
        mlist.setAdapter(mMyAdapter);

        mMyAdapter.notifyDataSetChanged();

    }

    private void initData() {
        for (int i = 0; i < 10; i++) {
            TicketInfo info = new TicketInfo();
            info.setValidity("20017.1.20-2017.3.28");
            info.setName_ktv("乐唱好声音KTV");
            info.setTicketprice("20");
            info.setAvailableprice("1000");
            list.add(info);

        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;


        }

    }

    private class MyAdapter extends BaseAdapter {
        private Context mContext;
        HashMap<Integer, View> lmap = new HashMap<Integer, View>();

       private  MyAdapter(Context context){
           this.mContext =context;
       }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public TicketInfo getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;

            if (lmap.get(position) == null) {
                convertView = LayoutInflater.from(mContext).inflate(R.layout.item_ticket, null);
                holder = new ViewHolder( convertView );
                convertView.setTag(holder);
                lmap.put(position,convertView);
            } else {
                convertView = lmap.get(position);
                holder = (ViewHolder) convertView.getTag();
            }

          final RelativeLayout  use = (RelativeLayout) convertView.findViewById(R.id.use_quan);


            final TextView tv = (TextView) convertView.findViewById(R.id.tv);
            TicketInfo info = getItem(position);
            holder.ticketprice.setText(info.getTicketprice());
            holder.availableprice.setText("满" + info.getAvailableprice() + "元可用");
            holder.name_ktv.setText(info.getName_ktv());
            holder.validity.setText(info.getValidity());


            final ViewHolder finalHolder = holder;
         tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {


//                    UiUtils.toast("点击了第"+ position +"条目");
//
//
//                    //
//
//                    mLq.setVisibility(View.VISIBLE);
//
//
//                    AlphaAnimation animation = new AlphaAnimation(1.0f,0.0f);
//                    animation.setDuration(1500);
//                    animation.setFillAfter(t);
//                    mLq.startAnimation(animation);
//
//
             tv .setTextColor(getResources().getColor(R.color.txt_small));
                    use.setBackground(getResources().getDrawable(R.mipmap.bkbg_1));
                tv .setText("已经领取");
//                  //  finalHolder.tv.setEnabled(false);
//
//
//
//                    list.remove(list.get(position));
//
//
//                     notifyDataSetChanged();


                }
            });


            return convertView;
        }
    }

    static class ViewHolder {

        TextView ticketprice;
        TextView availableprice;
        TextView name_ktv;
        TextView validity;
        RelativeLayout use;
        public ViewHolder(View convertView) {
           ticketprice = (TextView) convertView.findViewById(R.id.price_usable);

          availableprice = (TextView) convertView.findViewById(R.id.des);

           name_ktv = (TextView) convertView.findViewById(R.id.name);

           validity = (TextView) convertView.findViewById(R.id.validity);

        }



    }


}
